from flask import Blueprint, jsonify, request
from project.connect_db import con_my_sql

engineer_page = Blueprint('engineer_page', __name__)

# 从数据库中取出全部订单信息
@engineer_page.route('/show_all_orders')
def show_all_orders():
    code = "SELECT username, equipment_problem, equipment_type,user_contact FROM users_service_not_finish"
    cursor_ans = con_my_sql(code)
    cursor_select = cursor_ans.fetchall()

    return jsonify(cursor_select)
from flask import Blueprint, jsonify, request
from project.connect_db import con_my_sql

engineer_page = Blueprint('engineer_page', __name__)

# 从数据库中取出全部订单信息
@engineer_page.route('/show_all_orders')
def show_all_orders():
    code = "SELECT username, equipment_problem, equipment_type,user_contact FROM users_service_not_finish"
    cursor_ans = con_my_sql(code)
    cursor_select = cursor_ans.fetchall()

    return jsonify(cursor_select)

# 实现删除订单的功能
@engineer_page.route('/finish_order', methods = ['POST'])
def finish_order():
    try:
        username = request.args.get('username')
        equipment_problem = request.args.get('equipment_problem')
        equipment_type = request.args.get('equipment_type')
        user_contact = request.args.get('user_contact')

        code = "DELETE FROM users_service_not_finish WHERE username = '%s' and equipment_problem = '%s' and equipment_type = '%s' and user_contact = '%s'" % (username, equipment_problem, equipment_type, user_contact)
        con_my_sql(code)

        code = "INSERT INTO users_service_finish (username, equipment_problem, equipment_type, user_contact) VALUES ('%s', '%s', '%s', '%s')" % (username, equipment_problem, equipment_type, user_contact)
        con_my_sql(code)

        return jsonify({"success": True, "message": "工单处理成功"})

    except Exception as e:
        # 打印详细错误日志
        print(f"[ERROR] finish_order: {str(e)}")
        return jsonify({"error": f"服务器错误: {str(e)}"}), 500